<?php
$this->lang->load('template');
$this->load->view('admin/common/header',array('_user'=>$_user,'modules'=>$modules,'pageTitle'=>'文章管理'));
$posts = array(
  'attr' => array(
	  'class' => 'index'
  ),
  'fields' => array(
		'id' => array('label' => $this->lang->line('tpl_id'), 'is_sort'=>true ),
		'title' => array('label' => $this->lang->line('tpl_title'), 'is_sort'=>true ),
  		'is_show' => array('label' => $this->lang->line('tpl_ishow'),'filter'=>'__doFilter','is_sort'=>true ),
		'is_recommend' => array('label' => $this->lang->line('tpl_isrecommend'),'filter'=>'__doFilter','is_sort'=>true ),
		'is_top' => array('label' => $this->lang->line('tpl_istop'),'filter'=>'__doFilter','is_sort'=>true ),
		'is_hot' => array('label' => $this->lang->line('tpl_ishot'),'filter'=>'__doFilter','is_sort'=>true ),
		//'is_show' => array('label' => $this->lang->line('tpl_isshow'),'filter'=>'__doFilter','is_sort'=>true ),
		'sorts'	=>  array('label' => $this->lang->line('tpl_sorts'),'is_sort'=>true ),
  		'action'	=> array('label' => $this->lang->line('tpl_actions'),'filter'=>'__doFilter'  ),
	),
  'data' => isset($result['result']) ? $result['result'] : null,
);
function __doFilter($f,$r) {
	$str = isset($r[$f])?$r[$f]:'';
	if($f=='status' || $f=='post_status' || substr($f,0,2)=='is') {
		return sprintf('<img src="%s">',__st($r[$f]));
	}
	if($f=='action') {
		$str = '<a href="%s" class="edit_link" title="编辑"><img alt="Edit" src="'.base_url('images/admin/icons/edit.png').'" /></a>';
		$str .= '&nbsp;';
		$str .= '<a href="%s" class="remove_link" rel="'.$r['id'].'" title="删除"><img alt="Remove" src="'.base_url('images/admin/icons/delete.png').'" /></a>';
		$str .= '&nbsp;';
		return sprintf($str,base_url('admin/posts/edit/'.$r['id']),base_url('admin/posts/remove/'.$r['id']));
	}
	
	return $str;
}
?>
<style>
.tr span {
	clear:both;
	display:block;
	color:#999
}
</style>
<script language="javascript">
$(document).ready(function(){
	$('.remove_link').click(
		function(event){
			event.preventDefault();
			url = this.href+'?format=json';
			return Admin.remove(
				url,
				'您确定删除该数据吗？'
			);
		}
	);
	$('.sort_link').click(
		function(event){
			event.preventDefault();
			field = this.attributes['field'].value;;
			return urlRequest.setSort(field);
		}
	);
});
</script>
<div class="clear with-sidebar" id="content">
  <div class='toolbar'>
    <ul class='actions'>
      <li> <a href="<?=site_url('admin/posts/create')?>" class="button" id="new_item_link"><span><img alt="Add" src="<?=base_url('images/admin/icons/add.png')?>" /><?=$this->lang->line('tpl_act_add')?></span></a> </li>
    </ul>
    <br class='clear' />
  </div>
  <h1><?=$this->lang->line('tpl_lists')?></h1>
  <div id="new-item"></div>
  <?=htmlTable($posts);?>
  <?php 
  	if (isset($result['pager'])) :
  ?>
  <div id="pagination" class="pagination"> 
  	<?php
  		echo $result['pager']->create_links();
  	?>
  </div>
  <?php endif;?>
  <br class='clear' />
<?php $this->load->view('admin/posts/_search', array('categories'=>$categories));?>
</div>
<?php $this->load->view('admin/common/footer');?>